USE master
GO
IF EXISTS(SELECT name FROM sys.databases WHERE name = 'DHAA')
DROP DATABASE DHAA
GO
CREATE DATABASE DHAA
GO
USE DHAA
GO


DROP TABLE [dbo].[Admins]
GO
CREATE TABLE [dbo].[Admins] (
[AdminID] int NOT NULL ,
[UserName] varchar(50) NOT NULL ,
[PassWord] varchar(32) NOT NULL ,
[AdminName] nvarchar(100) NULL DEFAULT ('Administrator') 
)


GO

-- ----------------------------
-- Records of Admins
-- ----------------------------

-- ----------------------------
-- Table structure for [dbo].[Categories]
-- ----------------------------
DROP TABLE [dbo].[Categories]
GO
CREATE TABLE [dbo].[Categories] (
[CategoryID] int NOT NULL ,
[CategoryName] nvarchar(250) NOT NULL ,
[ParentID] int NOT NULL DEFAULT ((0)) ,
[Image] varchar(150) NULL ,
[Description] nvarchar(MAX) NULL 
)


GO

-- ----------------------------
-- Records of Categories
-- ----------------------------

-- ----------------------------
-- Table structure for [dbo].[Customers]
-- ----------------------------
DROP TABLE [dbo].[Customers]
GO
CREATE TABLE [dbo].[Customers] (
[CustomerID] int NOT NULL ,
[UserName] varchar(50) NOT NULL ,
[Password] varchar(32) NOT NULL ,
[CustomerName] nvarchar(100) NOT NULL 
)


GO

-- ----------------------------
-- Records of Customers
-- ----------------------------

-- ----------------------------
-- Table structure for [dbo].[FeedBack]
-- ----------------------------
DROP TABLE [dbo].[FeedBack]
GO
CREATE TABLE [dbo].[FeedBack] (
[FeedID] int NOT NULL ,
[FeedContent] nvarchar(250) NOT NULL ,
[CustomerID] int NOT NULL ,
[ProductID] int NOT NULL ,
[FeedDate] datetime NOT NULL DEFAULT '' 
)


GO

-- ----------------------------
-- Records of FeedBack
-- ----------------------------

-- ----------------------------
-- Table structure for [dbo].[Products]
-- ----------------------------
DROP TABLE [dbo].[Products]
GO
CREATE TABLE [dbo].[Products] (
[ProductID] int NOT NULL ,
[CategoryID] int NOT NULL ,
[ProductName] nvarchar(250) NOT NULL ,
[ProductImage] varchar(100) NOT NULL ,
[Price] float(53) NOT NULL ,
[Description] nvarchar(MAX) NULL ,
[FeedBackID] int NULL 
)


GO


ALTER TABLE [dbo].[Admins] ADD PRIMARY KEY ([AdminID])
GO

-- ----------------------------
-- Indexes structure for table Categories
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table [dbo].[Categories]
-- ----------------------------
ALTER TABLE [dbo].[Categories] ADD PRIMARY KEY ([CategoryID])
GO

-- ----------------------------
-- Indexes structure for table Customers
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table [dbo].[Customers]
-- ----------------------------
ALTER TABLE [dbo].[Customers] ADD PRIMARY KEY ([CustomerID])
GO

-- ----------------------------
-- Indexes structure for table FeedBack
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table [dbo].[FeedBack]
-- ----------------------------
ALTER TABLE [dbo].[FeedBack] ADD PRIMARY KEY ([FeedID])
GO

-- ----------------------------
-- Indexes structure for table Products
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table [dbo].[Products]
-- ----------------------------
ALTER TABLE [dbo].[Products] ADD PRIMARY KEY ([ProductID])
GO

-- ----------------------------
-- Indexes structure for table sysdiagrams
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table [dbo].[sysdiagrams]
-- ----------------------------
ALTER TABLE [dbo].[sysdiagrams] ADD PRIMARY KEY ([diagram_id])
GO

-- ----------------------------
-- Uniques structure for table [dbo].[sysdiagrams]
-- ----------------------------
ALTER TABLE [dbo].[sysdiagrams] ADD UNIQUE ([principal_id] ASC, [name] ASC)
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[FeedBack]
-- ----------------------------
ALTER TABLE [dbo].[FeedBack] ADD FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customers] ([CustomerID]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
ALTER TABLE [dbo].[FeedBack] ADD FOREIGN KEY ([ProductID]) REFERENCES [dbo].[Products] ([ProductID]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO

-- ----------------------------
-- Foreign Key structure for table [dbo].[Products]
-- ----------------------------
ALTER TABLE [dbo].[Products] ADD FOREIGN KEY ([CategoryID]) REFERENCES [dbo].[Categories] ([CategoryID]) ON DELETE NO ACTION ON UPDATE NO ACTION
GO
